/**
 * @projectName study-note
 * @package Cammand
 * @className Cammand.Test
 */
package Cammand;

/**
 * Test
 * @description 测试类
 * @author answer_wx
 * @date 2022/7/5 11:33
 * @version 1.0
 */
public class Test {
    public static void main(String[] args) {
        /**
         * 命令模式的一种用法，函数式编程
         */
        ProcessArray processArray = new ProcessArray();
        int[] arr = {-1, 2, 3, 8, 5, -8};
        // 第一次处理数据
        processArray.each(arr, new ICammand() {
            @Override
            public void process(int[] target) {
                for (int i : arr) {
                    System.out.println("按顺序输出数组数据：" + i);
                }
            }
        });
        System.out.println("----------分隔符-------");
        processArray.each(arr, new ICammand() {
            @Override
            public void process(int[] target) {
                int sum = 0;
                for (int i : arr) {
                    sum += i;
                }
                System.out.println("计算数组所有数据之和：" + sum);
            }
        });
        System.out.println("---------分隔符，命令模式第二种------");
        Receiver receiver = new Receiver();
        Cammand concreteCommand = new ConcreteCommand(receiver);
        Invoke invoke = new Invoke();
        invoke.setCammand(concreteCommand);
        invoke.executeCammand();
        invoke.submitCammand();
    }
}